/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.pp.ws;

import com.pp.entites.Evenement;
import com.pp.services.Evenement_ejbLocal;
import javax.ejb.EJB;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.Consumes;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.GET;
import javax.ws.rs.Produces;
import javax.enterprise.context.RequestScoped;
import javax.ws.rs.core.MultivaluedMap;

/**
 * REST Web Service
 *
 * @author arnaud
 */
@Path("entrant")
@RequestScoped
public class Entrant {
    @EJB
    private Evenement_ejbLocal evenementEjb;

    @Context
    private UriInfo context;
    

    /**
     * Creates a new instance of Entrant
     */
    public Entrant() {
    }

    /**
     * Retrieves representation of an instance of com.pp.ws.Entrant
     * @return an instance of java.lang.String
     */
    @GET
    @Produces("application/json")
    public String getJson() {
        MultivaluedMap<String, String> map = context.getQueryParameters();
        if(map == null || !map.containsKey("evenement")){
            return "error";
        }
        String evtString = map.getFirst("evenement");
        if(evtString == null || evtString.length()==0){
            return "error - evenement vide";
        }
        Evenement integrationOK = evenementEjb.IntegrationEvenement(evtString);
        if(integrationOK != null){
            return "{\"reponse\":\"ACK\",\"idCreateur\":\""+integrationOK.getEvenementPK().getIdCreateur()+"\",\"numEvenement\":"+integrationOK.getEvenementPK().getNumEvenement()+"}";
        }else{
            return "error";
        }
    }

    /**
     * PUT method for updating or creating an instance of Entrant
     * @param content representation for the resource
     * @return an HTTP response with content of the updated or created resource.
     */
    @PUT
    @Consumes("application/json")
    public void putJson(String content) {
    }
}
